//SPDX-FileCopyrightText: Copyright 2025-2025 深圳市同心圆网络有限公司
//SPDX-License-Identifier: GPL-3.0-only

import { fetch } from '@tauri-apps/plugin-http';
import type { AtomGitUser } from './common';

export async function get_self_info(accessToken: string): Promise<AtomGitUser> {
    const headers = [["Origin", ""], ["Authorization", `Bearer ${accessToken}`]] as [string, string][]; //fix http with unsafe-header return 403
    const url = `https://api.atomgit.com/user/info`;
    const res = await fetch(url, {
        method: "GET",
        headers: headers,
    });
    if (res.ok && res.status == 200) {
        return await res.json();
    } else {
        console.log(res);
        throw "error get user info";
    }
}